import AppConfig from './config/index.js'
import regeneratorRuntime from './lib/runtime/runtime'; //es7
!(function() {
  var PageTmp = Page;

  Page = function(pageConfig) {
    // 设置全局默认分享
    pageConfig = Object.assign(
      {
        onShareAppMessage: function() {
          return {
            title: "一羊千禧",
            path: "/pages/index/index" ,
            // imageUrl: "默认分享图片"
          };
        }
      },
      pageConfig
    );

    PageTmp(pageConfig);
  };
})();
//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })





    // 获取设备信息
   this.getSystemInfo();



  },


  getSystemInfo: function () {
      let t = this;
      wx.getSystemInfo({
          success: function (res) {
              t.globalData.systemInfo = res;
          }
      });
  },


  editTabbar: function () {
      let tabbar = this.globalData.tabBar;
      let currentPages = getCurrentPages();
      let _this = currentPages[currentPages.length - 1];
      let pagePath = _this.route;
      (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
      for (let i in tabbar.list) {
          tabbar.list[i].selected = false;
          (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
      }
      _this.setData({
          tabbar: tabbar
      });
  },

  globalData: {
    userInfo: null,
    host: AppConfig.server.host,
    imgBaseUrl: `${AppConfig.server.host}${AppConfig.server.staticPath}`,
    color: {
      goldLight: '#d3c985'
    },
    tabBar: {
            "backgroundColor": "#ffffff",
            "color": "#979795",
            "selectedColor": "#1c1c1b",
              "list": [{
                      "pagePath": "/pages/index/index",
                      "selectedIconPath": " ../../images/foot1_03.png",
                      "iconPath": "../../images/foot_03.png",
                      "text": "首页"
                  },
                  {
                      "pagePath": "/pages/shop/shop",
                      "selectedIconPath": "../../images/foot1_05.png",
                      "iconPath": "../../images/foot_05.png",
                      "text": "商城"
                  },
                  {
                      "pagePath": "/pages/sheep/sheep",
                      "selectedIconPath": "../../images/sheep_03.png",
                      "iconPath": "../../images/sheep_03.png",
                      "isSpecial": true,
                      "text": "爱心领养"
                  },
                  {
                      "pagePath": "/pages/cart/cart",
                      "selectedIconPath": "../../images/foot1_07.png",
                      "iconPath": "../../images/foot_07.png",
                      "text": "购物车"
                  },
                  {
                      "pagePath": "/pages/my/my",
                      "selectedIconPath": "../../images/foot1_09.png",
                      "iconPath": "../../images/foot_09.png",
                      "text": "我的"
                  }
              ]
       }
  }
})